package org.hot100_3;

public class leetcode34 {
    public int[] searchRange(int[] nums, int target) {

        int [] res = new int[2];

        int left = search(nums, target);
        int right = search(nums,target+1)-1;

        if ( left==nums.length || nums[left]!=target){
            res[0]=-1;
            res[1]=-1;
        }else {
            res[0]=left;
            res[1]=right;
        }

        return res;
    }

    private int search(int [] nums,int target){
        int left =0;
        int right = nums.length-1;

        while (left<=right){
            int mid =(left+right)>>>1;

            if (nums[mid]<target){
                left=mid+1;
            }else {
                right=mid-1;
            }
        }

        return left;
    }
}
